package com.aaa.service.impl;

import com.aaa.dao.EmpMapper;
import com.aaa.entity.Emp;
import com.aaa.service.EmpService;
import com.aaa.vo.EmpSearchForm;
import com.aaa.vo.Result;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description:
 * @author:LiWei
 * @date:2022年09月29日14:16
 */
@Service
public class EmpServiceImpl implements EmpService {

    @Autowired
    private EmpMapper empMapper;
    @Qualifier("emp")
    @Override
    public Result findAll(int currentPage, int pageSize, EmpSearchForm empSearchForm) {
        PageHelper.startPage(currentPage, pageSize);
        if (empSearchForm.getDate()!=null) {
            empSearchForm.setStartDate(empSearchForm.getDate()[0]);
            empSearchForm.setEndDate(empSearchForm.getDate()[1]);
        }

        List<Emp> emps = empMapper.findAll(empSearchForm);
        PageInfo<Emp> pageInfo = new PageInfo<>(emps);
        return new Result(200,"查询成功",pageInfo);
    }


    @Override
    public int add(Emp record) {
        int insert = empMapper.insert(record);
        return insert;
    }

    @Override
    public int delete(int id) {
        int i = empMapper.deleteByPrimaryKey(id);
        return i;
    }

    @Override
    public int update(Emp record) {
        int i = empMapper.updateByPrimaryKey(record);
        return i;
    }


}
